package com.xzzz.irda.guardcat.core.metric.compiler;

import java.io.Serializable;
import java.lang.management.CompilationMXBean;
import java.lang.management.ManagementFactory;

/**
 * 编译器信息
 *
 * @author xzzz
 * @since 1.0.0
 */
public class CompilerInfo implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 编译器名称
     */
    private String name;

    /**
     * 总编译时间
     */
    private long totalCompilationTime;

    /**
     * 构造器私有化
     */
    private CompilerInfo() {
    }

    /**
     * 获取编译器信息
     *
     * @return CompilerInfo 编译器信息
     */
    public static CompilerInfo getCompilerInfo() {
        CompilerInfo compilerInfo = new CompilerInfo();
        CompilationMXBean compilationMxBean = ManagementFactory.getCompilationMXBean();
        compilerInfo.name = compilationMxBean.getName();
        compilerInfo.totalCompilationTime = compilationMxBean.getTotalCompilationTime();
        return compilerInfo;
    }

    public String getName() {
        return name;
    }

    public long getTotalCompilationTime() {
        return totalCompilationTime;
    }

    @Override
    public String toString() {
        return "编译器信息{" +
                "名称='" + name + '\'' +
                ", 总编译时间='" + totalCompilationTime + "毫秒'" +
                '}';
    }

}
